import 'dotenv/config';
import { DataSource } from 'typeorm';
import { User } from '../models/User';
import { Group } from '../models/Group';
import { Website } from '../models/Website';

export const AppDataSource = new DataSource({
  type: 'mysql',
  host: process.env.DB_HOST || 'localhost',
  port: Number(process.env.DB_PORT) || 3306,
  username: process.env.DB_USERNAME || 'root',
  password: process.env.DB_PASSWORD || '',
  database: process.env.DB_DATABASE || 'qianxun',
  synchronize: process.env.NODE_ENV === 'development',
  logging: process.env.NODE_ENV === 'development',
  entities: [User, Group, Website],
  migrations: ['src/migrations/*.ts'],
  subscribers: ['src/subscribers/*.ts'],
  charset: 'utf8mb4',
  timezone: '+08:00',
  extra: {
    connectionLimit: 10,
  },
});